package hung.vnptthanhhoa.adapter;

import hung.vnptthanhhoa.cookingbook.R;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ArrayAdapter_Food extends ArrayAdapter<FoodList> {

	Activity context;
	ArrayList<FoodList> arrayList;

	public ArrayAdapter_Food(Activity context, ArrayList<FoodList> arrayList) {
		super(context, R.layout.item_listview_food);
		this.context = context;
		this.arrayList = arrayList;
	}

	public View getView(int position, View view, ViewGroup parent) {
		LayoutInflater inflater = context.getLayoutInflater();
		View rowView = inflater
				.inflate(R.layout.item_listview_food, null, true);
		TextView txtTitle = (TextView) rowView
				.findViewById(R.id.item_listview_food_text);
		ImageView imageView = (ImageView) rowView
				.findViewById(R.id.item_listview_food_img);
		TextView txtNote = (TextView) rowView
				.findViewById(R.id.item_listview_food_note);
		FoodList foodList = arrayList.get(position);
		txtTitle.setText(foodList.getName());
		imageView.setImageBitmap(BitmapFactory.decodeByteArray(
				foodList.getImage(), 0, foodList.getImage().length));
		txtNote.setText(foodList.getNote());
		// imageView.setImageResource(R.drawable.icon_canh);
		// imageView.setImageBitmap(bmp[position]);//
		// setImageResource(imageId[position]);

		return rowView;
	}

	// public Integer getFoodId(Integer position) {
	// return food_id[position];
	// }
	//
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public FoodList getItem(int position) {
		return arrayList.get(position);
	}
}